<?php
function index()
{
	global $db;
	global $params;
	global $tag;	// 标签数组
	global $request;
	global $dl;
	global $isdl;
	global $procat;

	if($request['p']==2){
		global $keyword;
		$keyword = '';
		$sql = "select * from ".TB_PREFIX."menu WHERE parentId =2";
		$procat = $db->get_results($sql);
		if(!empty($_POST)){
			$_SESSION[TB_PREFIX.'alltj'] = array();
			if(!empty($request['keyword'])&&$request['keyword']!='请输入要搜索的关键词'){
				$tj .=	" AND title like  '%".$request['keyword']."%'";
				$_SESSION[TB_PREFIX.'alltj']['keyword'] = $request['keyword'];	
				$keyword = $_SESSION[TB_PREFIX.'alltj']['keyword'];
				$sql = "SELECT * FROM ".TB_PREFIX."product WHERE 1=1 ".$tj;
				$sb = new sqlbuilder('mdt',$sql,'ordering DESC,id DESC',$db,4,true,URLREWRITE?'/':'./');
				if(!empty($sb->results))
				{
					foreach($sb->results as $k =>$v)
					{
						if(!empty($v['originalPic']))
						{
							$sb->results[$k]['originalPic'] = ispic($v['originalPic']);
							$sb->results[$k]['indexPic']	= ispic($v['indexPic']);
						}
					}
					$tag['data.product']=$sb->results;
					if($sb->totalPageNo()>1) 
					{
						$tag['pager.cn']=$sb->get_pager_show();
						$tag['pager.en']=$sb->get_en_pager_show();
					}
				}
				$sb=null;
			}
		}elseif($_SESSION[TB_PREFIX.'alltj'] && $request['mdtp']){
			if(!empty($_SESSION[TB_PREFIX.'alltj']['keyword'])){
				$tj = " AND title like '%".$_SESSION[TB_PREFIX.'alltj']['keyword']."%'";	
				$keyword = $_SESSION[TB_PREFIX.'alltj']['keyword'];
				$sql = "SELECT * FROM ".TB_PREFIX."product WHERE 1=1 ".$tj;
				$sb = new sqlbuilder('mdt',$sql,'ordering DESC,id DESC',$db,4,true,URLREWRITE?'/':'./');
				if(!empty($sb->results))
				{
					foreach($sb->results as $k =>$v)
					{
						if(!empty($v['originalPic']))
						{
							$sb->results[$k]['originalPic'] = ispic($v['originalPic']);
							$sb->results[$k]['indexPic']	= ispic($v['indexPic']);
						}
					}
					$tag['data.product']=$sb->results;
					if($sb->totalPageNo()>1) 
					{
						$tag['pager.cn']=$sb->get_pager_show();
						$tag['pager.en']=$sb->get_en_pager_show();
					}
				}
				$sb=null;
			}
		}else{
			$_SESSION[TB_PREFIX.'alltj'] = array();
		}
		
			
	}elseif($request['p']==11){
		if(!empty($_POST['keyword'])){
			$sql = "SELECT * FROM ".TB_PREFIX."agent WHERE wechat = '".$request['keyword']."'";
			$dl = $db->get_row($sql);
			$isdl = 1;
		}else{
			$isdl = 0;
				
		}
	}else{
	
		$sql="SELECT * FROM ".TB_PREFIX."article WHERE channelId=".$params['id'];
		$sb = new sqlbuilder('mdt',$sql,'pageId ASC',$db,1,true,URLREWRITE ? '/' : './');
		if(!empty($sb->results))
		{
			foreach($sb->results as $k =>$v)
			{
				$sb->results[$k]['originalPic'] = ispic($v['originalPic']);
				$sb->results[$k]['indexPic']	= ispic($v['indexPic']);
				if(!empty($sb->results[$k]['description']))$sb->results[$k]['description'] = '<div class="details"><h2>文章摘要:'.$sb->results[$k]['description'].'</h2></div>';
			}
			$tag['data.results']=$sb->results;
			if($sb->totalPageNo()>1) 
			{
				$tag['pager.cn']=$sb->get_pager_show();
				$tag['pager.en']=$sb->get_en_pager_show();
			}
		}
		
		//页面点击统计
		if($sb->results[0]['id'])
		{
			$sql='UPDATE '.TB_PREFIX.'article SET counts=counts+1 WHERE id='.$sb->results[0]['id'];
			$db->query($sql);
		}
		$sb=null;
	}
}
function getsec(){
	global $request,$db;
	$sql = "SELECT id FROM ".TB_PREFIX."menu WHERE title = '".$request['catname']."'";
	$id = $db->get_var($sql);
	$results = $db->get_results("SELECT title,id FROM ".TB_PREFIX."menu WHERE parentId=".$id);
	if(!empty($results)){
		foreach($results as $key => $value){
			$results[$key]->url = sys_href($value->id);	
		}	
	}
	$data['cid'] = sys_href($id);
	$data['results'] = $results; 
	echo json_encode($data);
	exit;	
}
?>